package com.ruoyi.web.controller.warn;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warn.domain.BusWaterWarnruleConditions;
import com.ruoyi.warn.service.IBusWaterWarnruleConditionsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预警规则条件Controller
 * 
 * @author maliang
 * @date 2025-09-10
 */
@RestController
@RequestMapping("/warn/warnrulecondition")
public class BusWaterWarnruleConditionsController extends BaseController
{
    @Autowired
    private IBusWaterWarnruleConditionsService busWaterWarnruleConditionsService;

    /**
     * 查询预警规则条件列表
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrulecondition:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusWaterWarnruleConditions busWaterWarnruleConditions)
    {
        startPage();
        List<BusWaterWarnruleConditions> list = busWaterWarnruleConditionsService.selectBusWaterWarnruleConditionsList(busWaterWarnruleConditions);
        return getDataTable(list);
    }

    /**
     * 导出预警规则条件列表
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrulecondition:export')")
    @Log(title = "预警规则条件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusWaterWarnruleConditions busWaterWarnruleConditions)
    {
        List<BusWaterWarnruleConditions> list = busWaterWarnruleConditionsService.selectBusWaterWarnruleConditionsList(busWaterWarnruleConditions);
        ExcelUtil<BusWaterWarnruleConditions> util = new ExcelUtil<BusWaterWarnruleConditions>(BusWaterWarnruleConditions.class);
        util.exportExcel(response, list, "预警规则条件数据");
    }

    /**
     * 获取预警规则条件详细信息
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrulecondition:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(busWaterWarnruleConditionsService.selectBusWaterWarnruleConditionsById(id));
    }

    /**
     * 新增预警规则条件
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrulecondition:add')")
    @Log(title = "预警规则条件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusWaterWarnruleConditions busWaterWarnruleConditions)
    {
        return toAjax(busWaterWarnruleConditionsService.insertBusWaterWarnruleConditions(busWaterWarnruleConditions));
    }

    /**
     * 修改预警规则条件
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrulecondition:edit')")
    @Log(title = "预警规则条件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BusWaterWarnruleConditions busWaterWarnruleConditions)
    {
        return toAjax(busWaterWarnruleConditionsService.updateBusWaterWarnruleConditions(busWaterWarnruleConditions));
    }

    /**
     * 删除预警规则条件
     */
    //@PreAuthorize("@ss.hasPermi('warn:warnrulecondition:remove')")
    @Log(title = "预警规则条件", businessType = BusinessType.DELETE)
	@PostMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(busWaterWarnruleConditionsService.deleteBusWaterWarnruleConditionsByIds(ids));
    }

    @PostMapping("/open/{id}")
    public AjaxResult open(@PathVariable String id)
    {
        BusWaterWarnruleConditions busWaterWarnruleConditions = busWaterWarnruleConditionsService.selectBusWaterWarnruleConditionsById(id);
        busWaterWarnruleConditions.setIsno("0");
        return toAjax(busWaterWarnruleConditionsService.updateBusWaterWarnruleConditions(busWaterWarnruleConditions));
    }

    @PostMapping("/close/{id}")
    public AjaxResult close(@PathVariable String id)
    {
        BusWaterWarnruleConditions busWaterWarnruleConditions = busWaterWarnruleConditionsService.selectBusWaterWarnruleConditionsById(id);
        busWaterWarnruleConditions.setIsno("1");
        return toAjax(busWaterWarnruleConditionsService.updateBusWaterWarnruleConditions(busWaterWarnruleConditions));
    }
}
